﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Wicresoft.EKA.Atrium.WebService.CMDBQueriesbyPath;

namespace Wicresoft.EKA.Atrium.WebService
{
    public class CMDBQuerybyPath
    {
        //public Security Sercuirty { get; set; }
        //[SoapHeader("Sercuirty")]
        public void ListInstances()
        {
            System.Net.ServicePointManager.ServerCertificateValidationCallback = TrustAllCertificatePolicy.CheckValidationResult;
            atrium_query proxy = new atrium_query();
            proxy.Sercuirty = Security.GetSecuritySoapHeader("Demo", "Pass01!");

            //proxy.Credentials = new NetworkCredential("admin", "Pass01!", "");

           


            var x = proxy.QueryByPath(new QueryByPath()
                     {
                         executeOption = QueryExecuteOption.EXECUTE_ONLY,
                         input = new QueryByPathInput()
                         {
                             query = new Query()
                             {
                                 Item = new QueryInput()
                                 {
                                     datasetId = "BMC.ASSET",
                                     datasetMask = GetMask.DATASET_MODE_CURRENT,
                                     queryObjects = new QueryObjectSel[]{
                                     new QueryObjectSel() {
                                        Item=new QueryObjectRegular()
                                        {
                                            alias="class1",
                                            classNameId=new ClassNameId()
                                            {
                                                namespaceName="BMC.CORE",
                                                className="BMC_Application",
                                            },
                                            qualification= new   QueryQualifier()
                                            {                                                
                                            
                                                Item=    new   QueryQualifierSimpleOp()
                                                {
                                                attribute="Name",
                                                operation=QueryQualifierOperation.EQUAL,
                                                operandRight= new QueryQualifierValue() {
                                                    Item=new QueryQualifierValueTypeValue()
                                                    {
                                                        value= new  Value ()
                                                        {
                                                          Item=  "BMC_Application_2",
                                                          ItemElementName=ItemChoiceType.stringValue
                                                        }
                                                    }                                                    
                                                }


                                               // Item=  new QueryQualifierOpAnd(){   
                                                    
                                               //   operandLeft=  new  QueryQualifier()
                                               //   {
                                                      
                                               //  Item=new      QueryQualifierSimpleOp()
                                               // {
                                               // attribute="Name",
                                               // operation=QueryQualifierOperation.EQUAL,
                                               // operandRight= new QueryQualifierValue() {
                                               //     Item=new QueryQualifierValueTypeValue()
                                               //     {
                                               //         value= new  Value ()
                                               //         {
                                               //           Item=  "BMC_Application_2",
                                               //           ItemElementName=ItemChoiceType.stringValue
                                               //         }
                                               //     }                                                    
                                               // }
                                               // }
                                               //   },
                                               //operandRight=  new  QueryQualifier()
                                               //   {
                                                      
                                               //  Item=new      QueryQualifierSimpleOp()
                                               // {
                                               // attribute="Name",
                                               // operation=QueryQualifierOperation.EQUAL,
                                               // operandRight= new QueryQualifierValue() {
                                               //     Item=new QueryQualifierValueTypeValue()
                                               //     {
                                               //         value= new  Value ()
                                               //         {
                                               //           Item=  "BMC_Application_2",
                                               //           ItemElementName=ItemChoiceType.stringValue
                                               //         }
                                               //     }                                                    
                                               // }
                                               // }
                                               //   },
                                        }
                                            }
                                        }
                                    },
                                       new QueryObjectSel() {
                                        Item=new QueryObjectRelationship()
                                        {
                                            alias="relationship1",
                                            classNameId=new ClassNameId()
                                            {
                                                namespaceName="BMC.CORE",
                                                className="BMC_ApplicationSystemServices",
                                            },
                                            qualification=null,
                                            direction=RelationshipDirection.OUT
                                        }
                                                                        },
                                        new QueryObjectSel() {
                                        Item=new QueryObjectRegular()
                                        {
                                            alias="class2",
                                            classNameId=new ClassNameId()
                                            {
                                                namespaceName="BMC.CORE",
                                                className="BMC_ApplicationService",
                                            },
                                            qualification=null
                                        }
                                    }

                                    },
                                     queryObjectSelectorList = new QueryObjectSelectorList()
                                     {
                                         list = new QueryObjectSelector[] { 
                                        new QueryObjectSelector()
                                        {
                                            alias="class1",
                                            attributes=new string[]{ "Name"}
                                        },
                                        new QueryObjectSelector()
                                        {
                                            alias="class2",
                                            attributes=new string[]{ "Name"}
                                        }
                                         }
                                     }
                                 }
                             }
                         }
                     });

            var y = 1;

        }
    }
}
